﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HRM.Entity;
using HRM.BIZ;
using WebUI.UserControls;

namespace WebUI.Pages
{
    public partial class RelationshipStatusManagement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadData();
            }
        }

        protected void LoadData()
        {
            RelationshipStatusTypeBiz relBiz = new RelationshipStatusTypeBiz();
            ucRelationshipStatusManagement.DataSource = relBiz.GetAll();
            ucRelationshipStatusManagement.LoadItemList();
        }

        protected void ucRelationshipStatusManagement_AddItem(object sender, ItemManagementEventArgs e)
        {
            RelationshipStatusTypeBiz relBiz = new RelationshipStatusTypeBiz();
            RelationshipStatusType rel = new RelationshipStatusType();
            rel.Name = e.Name;
            relBiz.Add(rel);
            (Master as DefaultMasterPage).RunStartupScript("displayMessage('Thêm thành công')");
            ucRelationshipStatusManagement.SetActionPanelVisible(false);
            LoadData();
        }

        protected void ucRelationshipStatusManagement_SaveEditItem(object sender, ItemManagementEventArgs e)
        {
            RelationshipStatusTypeBiz relBiz = new RelationshipStatusTypeBiz();
            RelationshipStatusType rel = relBiz.GetByID(e.ID);
            if (rel != null)
            {
                rel.Name = e.Name;
                relBiz.Update(rel);
                (Master as DefaultMasterPage).RunStartupScript("displayMessage('Cập nhật thành công')");
                ucRelationshipStatusManagement.SetActionPanelVisible(false);
                LoadData();
            }
        }

        protected void ucRelationshipStatusManagement_DeleteItem(object sender, ItemManagementEventArgs e)
        {
            RelationshipStatusTypeBiz relBiz = new RelationshipStatusTypeBiz();
            relBiz.Delete(e.ID);
            LoadData();
        }
    }
}
